<?php
namespace app\home\controller;
use \think\Controller;
use app\home\model\CommunityModel;
use app\home\model\TopicsModel;
class Community extends Controller
{
    /**
     * 社区首页
     */
    public function index(){
        $community = new  CommunityModel();
        $communityList = $community->communityList();

        foreach($communityList as $key => $value){
            $community_id = $value['id'];
            $topics = new TopicsModel();
            $topicsCount = $topics->topicsCount($community_id);
            $topicsList = $topics->topicsList($community_id);

            $communityList[$key]['topicsCount'] = $topicsCount;
            $communityList[$key]['topicsList'] = $topicsList;
        }

        $this->assign('communityList', $communityList);
        $this->assign('topics', $communityList);
        return $this->fetch('index');
    }


}